/**
  *@description '任务开发选项卡选中'
  *@param taskTabsActive
  *@description '工作流选项卡选中'
  *@param workTabsActive
  *@description '用于获取具体的任务组件'
  *@param taskTabs.type
  *@description '用于获取任务组件'
  *@param taskTabs.comp
  *@description '与选项卡绑定值 value 对应的标识符，表示选项卡别名,值唯一'
  *@param taskTabs.name
  *@description '选项卡标题	'
  *@param taskTabs.label
*/
const state = {
  taskTabs: [],
  taskTabsActive: '',
  workTabs: [],
  workTabsActive: '',
  dataTabs: [],
  dataTabsActive: '',
  tableTabs: [],
  tableTabsActive: '',
  computedTabs: [],
  computedTabsActive: ''
}
const mutations = {
  // 任务table
  ADD_TASK_TABS(state, data) {
    state[data.tabsName + 'Active'] = data.taskType + (data.treeId || data.id)
    for (const option of state[data.tabsName]) {
      if (option.taskType + (option.treeId || option.id) === state[data.tabsName + 'Active']) {
        return
      }
    }
    state[data.tabsName].push(data)
  },
  // 删除tabs
  DEL_TASK_TABS(state, { tabsName, targetName }) {
    const tabs = state[tabsName]
    tabs.forEach((tab, index) => {
      if (tab.taskType + (tab.treeId || tab.id) === targetName) {
        const nextTab = tabs[index + 1] || tabs[index - 1]
        if (nextTab) {
          state[tabsName + 'Active'] = nextTab.taskType + (nextTab.treeId || nextTab.id)
        }
      }
    })
    state[tabsName] = tabs.filter(data => {
      return data.taskType + (data.treeId || data.id) !== targetName
    })
  },
  // 修改Tab 必须要传id
  EDIT_TAB(state, data) {
    state[data.tabsName].map(item => {
      if (item.taskType + (item.treeId || item.id) === data.taskType + (data.treeId || data.id)) {
        Object.assign(item, data)
      }
    })
  },
  UPDATA_ACTIVES(state, data) {
    state[data.tabsName + 'Active'] = data.taskType + (data.treeId || data.id)
  }

}

export default {
  namespaced: true,
  state,
  mutations
}
